package com.leyou.order.web;


import com.leyou.order.dto.OrderDTO;
import com.leyou.order.dto.vo.OrderVO;
import com.leyou.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderDTO orderDTO){


        return ResponseEntity.status(HttpStatus.CREATED).body(orderService.createOrder(orderDTO));
    }

    /**
     * 根据订单id查询订单
     * @param orderId 订单id
     * @return        订单详情
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderVO> queryOrderById(@PathVariable("id") Long orderId){

        return ResponseEntity.ok(orderService.queryOrderById(orderId));
    }

    /**
     * 根据id查询付款地址
     * @param orderId
     * @return
     */
    @GetMapping("/url/{id}")
    public ResponseEntity<String> getPayUrl(@PathVariable("id") Long orderId){
        return ResponseEntity.ok(orderService.getPayUrl(orderId));
    }

    @GetMapping("/state/{id}")
    public ResponseEntity<Integer> queryPayState(@PathVariable("id") Long id){

        return ResponseEntity.ok(orderService.queryPayState(id));
    }
}
